//
//  BaseTabBarViewController.m
//  JiCheHuiiOS
//
//  Created by 邢广范 on 2016/12/12.
//  Copyright © 2016年 邢广范. All rights reserved.
//

#import "BaseTabBarViewController.h"
#import "BaseNavigationViewController.h"
#import "MainViewController.h"
#import "MessageViewController.h"
#import "GameViewController.h"
#import "VideoViewController.h"
#import "MineViewController.h"

@interface BaseTabBarViewController ()

@end

@implementation BaseTabBarViewController

- (void)setupTabBar
{
    //    //初始化子控制器
    MainViewController *mainVc = [[MainViewController alloc] init];
    [self addChildViewController:mainVc title:@"首页" image:@"unfind" selectedImage:@"find"];
    
    MessageViewController *messageVc = [[MessageViewController alloc] init];
    [self addChildViewController:messageVc title:@"消息" image:@"unmessage" selectedImage:@"message"];
    
    GameViewController *gameVc = [[GameViewController alloc] init];
    [self addChildViewController:gameVc title:@"摇钱树" image:@"ungame" selectedImage:@"game"];
    
    VideoViewController *videoVc = [[VideoViewController alloc] init];
    [self addChildViewController:videoVc title:@"视频秀" image:@"unvideo" selectedImage:@"video"];
    
    MineViewController *mineVc = [[MineViewController alloc] init];
    [self addChildViewController:mineVc title:@"我的" image:@"unmine" selectedImage:@"mine"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTabBar];
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(0xfc567f), NSFontAttributeName:[UIFont systemFontOfSize:11.f]} forState:UIControlStateSelected];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(0x9A9A9A), NSFontAttributeName:[UIFont systemFontOfSize:11.f]} forState:UIControlStateNormal];

    // Do any additional setup after loading the view.
}

-(void)addChildViewController:(UIViewController *)childController title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    
    
    childController.title = title;
    
    childController.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NSDictionary *dicNor = @{
                             NSForegroundColorAttributeName:RGB(0x9A9A9A)
                             
                             };
    
    
    [childController.tabBarItem setTitleTextAttributes:dicNor forState:UIControlStateNormal];
    
    NSDictionary *dicSelected = @{
                                  NSForegroundColorAttributeName:RGB(0xfc567f)
                                  
                                  };
    
    
    [childController.tabBarItem setTitleTextAttributes:dicSelected forState:UIControlStateSelected];
    // 先把外面传进来的控制器包装成一个导航控制器
    BaseNavigationViewController *mainNav = [[BaseNavigationViewController alloc ]initWithRootViewController:childController];
    // 添加子控制器
    [self addChildViewController:mainNav];
}

     
    

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
